package com.example.professorevaluation.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.professorevaluation.R
import com.example.professorevaluation.bean.ProfessorBean


/**
 *@author: wangtianxiong
 *@time: 2022/3/29
 *@describe:
 *
 */
class ProfessorAdapter(var list: List<ProfessorBean>, var context: Context) :
    RecyclerView.Adapter<ProfessorAdapter.TestViewHolder>() {

    interface OnItemClick{
        fun data(bean: ProfessorBean)
    }
    private var mCallback: OnItemClick? = null
    class TestViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        var textView: TextView = view.findViewById(R.id.tv_name)
        var llLayout: LinearLayout = view.findViewById(R.id.ll_layout)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TestViewHolder {
        return TestViewHolder(
            LayoutInflater.from(
                context
            ).inflate(
                R.layout.item_main, parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: TestViewHolder, position: Int) {
        holder.textView.text = list[position].name
        holder.llLayout.setOnClickListener {
            mCallback?.data(list[position])
        }
    }

    override fun getItemCount(): Int {
        return list.size
    }

    fun setOnItemClick(callback: OnItemClick){
        mCallback = callback
    }



}